import { _decorator, ColliderComponent, Component, Node, RigidBody, v3, Vec3 } from 'cc';
import { PoolManager } from './AshFramework/Managers/PoolManager';
const { ccclass, property } = _decorator;

@ccclass('ItemController')
export class ItemController extends Component {

    rigidBody: RigidBody;
    collider: ColliderComponent;
    itemNode: Node;
    index: number = 0;
    damage: number = 0;

    worldScale: Vec3 = v3(1, 1, 1);

    Init(index: number, damage: number, show: boolean = false) {
        this.index = index;
        this.damage = damage;
        this.node.children.forEach(e => {
            e.active = e.name == `${index}`;
            if (e.active) {
                this.rigidBody = e.getComponent(RigidBody);
                this.collider = e.getComponent(ColliderComponent);
                this.itemNode = e;
                this.itemNode.getWorldScale(this.worldScale);
            }
        });

        this.RigidEnable(!show);
    }

    RigidEnable(enable: boolean = true) {
        this.rigidBody.enabled = enable;
        this.collider.enabled = enable;
    }

    DelayDestroy(seconds: number = 10) {
        this.scheduleOnce(() => {
            this.node.destroy();
            // PoolManager.PutNode(this.node);
        }, seconds)
    }

}


